{extend name="base" /}

{block name="box"}
<!--<div class="layui-hide-xs">-->
<!--<div class="fly-panel fly-column">-->
<!--<div class="layui-container">-->
<!--<ul class="layui-clear">-->
<!--<li class="layui-hide-xs"><a href="/">首页</a></li>-->
<!--<li class="layui-this"><a href="">提问</a></li>-->
<!--<li><a href="">分享<span class="layui-badge-dot"></span></a></li>-->
<!--<li><a href="">讨论</a></li>-->
<!--<li><a href="">建议</a></li>-->
<!--<li><a href="">公告</a></li>-->
<!--<li><a href="">动态</a></li>-->
<!--<li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block"><span class="fly-mid"></span></li>-->

<!--&lt;!&ndash; 用户登入后显示 &ndash;&gt;-->
<!--<li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block"><a href="../user/index.html">我发表的贴</a></li>-->
<!--<li class="layui-hide-xs layui-hide-sm layui-show-md-inline-block"><a href="../user/index.html#collection">我收藏的贴</a></li>-->
<!--</ul>-->

<!--<div class="fly-column-right layui-hide-xs">-->
<!--<span class="fly-search"><i class="layui-icon"></i></span>-->
<!--<a href="add.html" class="layui-btn">发表新帖</a>-->
<!--</div>-->
<!--<div class="layui-hide-sm layui-show-xs-block" style="margin-top: -10px; padding-bottom: 10px; text-align: center;">-->
<!--<a href="add.html" class="layui-btn">发表新帖</a>-->
<!--</div>-->
<!--</div>-->
<!--</div>-->
<!--</div>-->

<div class="layui-container">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md8 content detail">
            <div class="fly-panel detail-box">
                <h1>{{$cardInfo.name}}</h1>
                <div class="fly-detail-info">
                    <!-- <span class="layui-badge">审核中</span> -->
                    <span class="layui-badge layui-bg-green fly-detail-column">{{$cardInfo.category_name}}</span>

                    {switch name="$cardInfo.is_end"}
                    {case value="1"}<span class="layui-badge" style="background-color: #999;">未结</span>{/case}
                    {case value="2"}<span class="layui-badge" style="background-color: #5FB878;">已结</span>{/case}
                    {/switch}

                    {eq name="$cardInfo.is_first" value="1"}
                    <span class="layui-badge layui-bg-black">置顶</span>
                    {/eq}

                    {eq name="$cardInfo.is_fine" value="1"}
                    <span class="layui-badge layui-bg-red">精帖</span>
                    {/eq}


                <span class="fly-list-nums">
                    <a href="#comment"><i class="iconfont" title="回答">&#xe60c;</i> {{$cardInfo.evaluate_num}}</a>
                    <i class="iconfont" title="人气">&#xe60b;</i> {{$cardInfo.browse}}
                    <i class="layui-icon" id="coll" title="收藏" onclick="collect(this)">&#xe600;</i>
                    <input type="hidden" value="{{$cardInfo.id}}">
                    <span id="collect">{{$cardInfo.collect_num}}</span>

                </span>
                </div>
                <div class="detail-about">
                    <a class="fly-avatar" href="{{:url('User/home',['id'=>$cardInfo.user_id])}}">
                        {if condition="empty($cardInfo.image)"}
                        <img src="__STATIC__/head.jpg" alt="{{$cardInfo.username}}">
                        {else/}
                        <img src="{{:get_img_url('__STATIC__/../upload/headImg/',$cardInfo['image'],0)}}" alt="{{$cardInfo.username}}">
                        {/if}
                    </a>
                    <div class="fly-detail-user">
                        <a href="{{:url('User/home',['id'=>$cardInfo.user_id])}}" class="fly-link">
                            <cite>{{$cardInfo.username}}</cite>
                            {gt name="$cardInfo.level" value="0"}
                            <i class="iconfont icon-renzheng" title="认证信息：{{ rows.user.approve }}"></i>
                            {/gt}

                            <i class="layui-badge fly-badge-vip">
                                {switch name="$cardInfo.level"}
                                {case value="0"}普通用户{/case}
                                {case value="1"}VIP1{/case}
                                {case value="2"}VIP2{/case}
                                {case value="3"}VIP3{/case}
                                {case value="4"}VIP4{/case}
                                {case value="5"}VIP5{/case}
                                {/switch}
                            </i>
                        </a>
                        <!--<span>{{$cardInfo.create_time}}</span>-->
                    </div>
                    <div class="detail-hits" id="LAY_jieAdmin" data-id="123">
                        {eq name="$cardInfo.sort" value="1"}
                        <span style="padding-right: 10px; color: #FF7200">悬赏：{{$cardInfo.gold}}金币</span>
                        {/eq}

                        <!--<span class="layui-btn layui-btn-xs jie-admin" type="edit"><a href="add.html">  </a></span>-->
                        <span class="time">{{$cardInfo.create_time}}</span>
                    </div>
                </div>
                <div class="detail-body photos">
                    {{$cardInfo.content}}
                </div>
            </div>

            <div class="fly-panel detail-box" id="flyReply">
                <fieldset class="layui-elem-field layui-field-title" style="text-align: center;">
                    <legend>回帖</legend>
                </fieldset>

                <ul class="jieda" id="jieda">
                    {if condition="!empty($evalList)"}
                    {foreach name="evalList" item="val"}
                    <li data-id="111">
                        <a name="item-1111111111"></a>
                        <div class="detail-about detail-about-reply" id="take_{{$val.id}}">
                            <a class="fly-avatar" href="{{:url('User/home',['id'=>$val.user_id])}}">
                                {if condition="empty($val.image)"}
                                <img src="__STATIC__/head.jpg" alt="{{$val.username}}">
                                {else/}
                                <img src="{{:get_img_url('__STATIC__/../upload/headImg/',$val['image'],0)}}" alt="{{$val.username}}">
                                {/if}
                            </a>
                            <div class="fly-detail-user">
                                <a href="{{:url('User/home',['id'=>$val.user_id])}}" class="fly-link">
                                    <cite>{{$val.username}}</cite>&nbsp;
                                    {gt name="$val.level" value="0"}
                                    <i class="iconfont icon-renzheng" title="认证信息：{{ rows.user.approve }}"></i>
                                    {/gt}

                                    <i class="layui-badge fly-badge-vip">
                                        {switch name="$val.level"}
                                        {case value="0"}普通用户{/case}
                                        {case value="1"}VIP1{/case}
                                        {case value="2"}VIP2{/case}
                                        {case value="3"}VIP3{/case}
                                        {case value="4"}VIP4{/case}
                                        {case value="5"}VIP5{/case}
                                        {/switch}
                                    </i>
                                </a>
                                {eq name="$val.user_id" value="$cardInfo.id"}
                                <span>(楼主)</span>
                                {/eq}
                            </div>
                            <div class="detail-hits">
                                <span class="time">{{$val.create_time}}</span>
                            </div>
                            {if condition="!empty($val.take)"}
                            <i class="iconfont icon-caina" title="最佳答案"></i>
                            {/if}
                            <!--<i class="iconfont icon-caina" title="最佳答案"></i>-->
                        </div>
                        <div class="detail-body jieda-body photos">
                            {{$val.eval_content}}
                        </div>
                        <div class="jieda-reply">
                            <span class="jieda-zan" type="zan" id="zan" onclick="changeZan(this)">
                                <i class="iconfont icon-zan"></i>
                                <em id="zan_num">{{$val.zan}}</em>
                            </span>
                            <!--帖子id-->
                            <input type="hidden" name="card_id" value="{{$cardInfo.id}}">
                            <!--评论id-->
                            <input type="hidden" name="id" value="{{$val.id}}">
                            <span type="reply" onclick="reply(this)">
                                <a href="#comment">
                                    <i class="iconfont icon-svgmoban53"></i>
                                    回复
                                </a>
                            </span>
                            <input type="hidden" name="username" value="{{$val.username}}">
                            <input type="hidden" name="url" value="{{:url('User/home',['id'=>$val.user_id])}}">
                            {eq name="$cardInfo.sort" value="1"}
                            {if condition="empty($cardInfo.good_user_id)"}
                            <div class="jieda-admin">
                                <span class="jieda-accept card_take" type="accept" onclick="take(this)">采纳</span>
                                <!--帖子主人的id-->
                                <input type="hidden" value="{{$cardInfo.user_id}}">
                                <!--帖子的id-->
                                <input type="hidden" value="{{$cardInfo.id}}">
                                <!--这条评论的id-->
                                <input type="hidden" value="{{$val.id}}">
                                <!--发这条评论人的id-->
                                <input type="hidden" value="{{$val.user_id}}">
                            </div>
                            {/if}
                            {/eq}
                        </div>
                    </li>
                    {/foreach}
                    <!--分页显示-->
                    {{$evalPage}}
                    {else/}
                    <li class="fly-none">消灭零回复</li>
                    {/if}
                </ul>

                <div class="layui-form layui-form-pane">
                    <form action="{{:url('Card/reply')}}" method="post">
                        <div class="layui-form-item layui-form-text">
                            <a name="comment"></a>
                            <!-- 加载编辑器的容器 -->
                            <div class="layui-input-block" style="z-index: 998">
                                <script id="container" name="content1" type="text/plain" style="height: 200px;" ></script>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <input type="hidden" name="card_id" value="{{$cardInfo.id}}">
                            <button class="layui-btn"  lay-submit>提交回复</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <div class="layui-col-md4">
            <dl class="fly-panel fly-list-one">
                <dt class="fly-panel-title">本周热议</dt>
                <dd>
                    <a href="">基于 layui 的极简社区页面模版</a>
                    <span><i class="iconfont icon-pinglun1"></i> 16</span>
                </dd>
                <dd>
                    <a href="">基于 layui 的极简社区页面模版</a>
                    <span><i class="iconfont icon-pinglun1"></i> 16</span>
                </dd>
                <dd>
                    <a href="">基于 layui 的极简社区页面模版</a>
                    <span><i class="iconfont icon-pinglun1"></i> 16</span>
                </dd>
                <dd>
                    <a href="">基于 layui 的极简社区页面模版</a>
                    <span><i class="iconfont icon-pinglun1"></i> 16</span>
                </dd>
                <dd>
                    <a href="">基于 layui 的极简社区页面模版</a>
                    <span><i class="iconfont icon-pinglun1"></i> 16</span>
                </dd>
                <dd>
                    <a href="">基于 layui 的极简社区页面模版</a>
                    <span><i class="iconfont icon-pinglun1"></i> 16</span>
                </dd>
                <dd>
                    <a href="">基于 layui 的极简社区页面模版</a>
                    <span><i class="iconfont icon-pinglun1"></i> 16</span>
                </dd>
                <dd>
                    <a href="">基于 layui 的极简社区页面模版</a>
                    <span><i class="iconfont icon-pinglun1"></i> 16</span>
                </dd>
                <dd>
                    <a href="">基于 layui 的极简社区页面模版</a>
                    <span><i class="iconfont icon-pinglun1"></i> 16</span>
                </dd>
                <dd>
                    <a href="">基于 layui 的极简社区页面模版</a>
                    <span><i class="iconfont icon-pinglun1"></i> 16</span>
                </dd>

                <!-- 无数据时 -->
                <!--
                <div class="fly-none">没有相关数据</div>
                -->
            </dl>

            <div class="fly-panel">
                <div class="fly-panel-title">
                    这里可作为广告区域
                </div>
                <div class="fly-panel-main">
                    <a href="http://layim.layui.com/?from=fly" target="_blank" class="fly-zanzhu" time-limit="2017.09.25-2099.01.01" style="background-color: #5FB878;">LayIM 3.0 - layui 旗舰之作</a>
                </div>
            </div>

            <div class="fly-panel" style="padding: 20px 0; text-align: center;">
                <img src="../../res/images/weixin.jpg" style="max-width: 100%;" alt="layui">
                <p style="position: relative; color: #666;">微信扫码关注 layui 公众号</p>
            </div>

        </div>
    </div>
</div>

<div class="fly-footer">
    <p><a href="http://fly.layui.com/" target="_blank">Fly社区</a> 2017 &copy; <a href="http://www.layui.com/" target="_blank">layui.com 出品</a></p>
    <p>
        <a href="http://fly.layui.com/jie/3147/" target="_blank">付费计划</a>
        <a href="http://www.layui.com/template/fly/" target="_blank">获取Fly社区模版</a>
        <a href="http://fly.layui.com/jie/2461/" target="_blank">微信公众号</a>
    </p>
</div>

<!-- 配置文件 -->
<script type="text/javascript" src="__STATIC__/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__STATIC__/ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
    var ue = UE.getEditor('container');
</script>

<script>
    $(function(){
        //已进入页面就执行,判断该贴是否已经被收藏
        var CardId = $("#coll").next().val();
        $.ajax({
            type : "get",
            url : "{{:url('Collect/showCollect')}}",
            data : {card_id:CardId},
            success : function(msg){
                if(msg == 1){
                    $("#coll").replaceWith('<i class="layui-icon" title="收藏" onclick="collect(this)">&#xe658;</i>');
                }else if(msg == 0){
                    $("#coll").replaceWith('<i class="layui-icon" title="收藏" onclick="collect(this)">&#xe600;</i>');
                }
            }
        })
    })

    $(".time").each(function(){
        var time = $(this).text();
        time = time.substring(0,10);
        $(this).text(time);
    })
    //点赞
    function changeZan(obj){
//        console.log($(obj).next().val());
        var card_id = $(obj).next().val();//帖子id
        var eval_id = $(obj).next().next().val();//评论id
//        var zan_num = $(obj).children("em").text();
//        console.log(zan_num);
        $.ajax({
            type : "get",
            url : "{{:url('Evaluate/zan')}}",
            data : {id:card_id,evalId:eval_id},
            success : function(data){
                var zan_num = $(obj).children("em").text();
                console.log(data);
                if(data == 0){
                    alert("请先登录");
                    document.location.href="{{:url('User/login')}}";
                }else if(data == 1){
                    zan_num = parseInt(zan_num) + 1;
                    $(obj).children("em").text(zan_num)
                    $(obj).addClass("zanok");
                }else if(data == 2){
                    zan_num = parseInt(zan_num) - 1;
                    $(obj).children("em").text(zan_num)
                    $(obj).removeClass("zanok");
                }

            }
        })
    }
    //回帖
    function reply(obj){
        var name = $(obj).next().val();
        var url = $(obj).next().next().val();
        console.log(url);
        name = "<a href='"+url+"'>@"+name+"</a>";

        ue.setContent(name);
    }
    //采纳
    function take(obj){
        <!--帖子主人的id-->
        var userId = $(obj).next().val();
        <!--帖子的id-->
        var cardId = $(obj).next().next().val();
        <!--这条评论的id-->
        var evalId = $(obj).next().next().next().val();
        <!--发这条评论人的id-->
        var evalUserId = $(obj).next().next().next().next().val();
        $.ajax({
            type : "get",
            url : "{{:url('Evaluate/take')}}",
            data : {id:userId,card_id:cardId,eval_id:evalId,eval_user_id:evalUserId},
            success : function(msg){
                if(msg == 0){
                    layer.open({
                        title: '错误提示'
                        ,content: '您还没有登录,或者您不是本帖子的贴主'
                    });
                }else if(msg == 1){
                    layer.open({
                        title: '错误提示'
                        ,content: '采纳失败'
                    });
                }else if(msg == 2){
                    $("#take_"+evalId).append('<i class="iconfont icon-caina" title="最佳答案"></i>');
                    $(".card_take").empty();
                }
            }
        })
    }
    //收藏
    function collect(obj){
        var cardId = $(obj).next().val();
        var collect_num = parseInt($("#collect").text());
        $.ajax({
            type : "get",
            url : "{{:url('Collect/collect')}}",
            data : {card_id:cardId},
            success : function(msg){
                if(msg == 0){
                    layer.open({
                        title: '错误提示'
                        ,content: '您还没有登录,不能收藏此贴'
                    });
                }else if(msg == 1){
                    $("#collect").text(collect_num+1);
                    $(obj).replaceWith('<i class="layui-icon" title="收藏" onclick="collect(this)">&#xe658;</i>');
                }else if(msg == 2){
                    $("#collect").text(collect_num-1);
                    $(obj).replaceWith('<i class="layui-icon" title="收藏" onclick="collect(this)">&#xe600;</i>');
                }else if(msg == 3){
                    layer.open({
                        title: '错误提示'
                        ,content: '收藏失败'
                    });
                }
            }
        })
    }
</script>
{/block}